package com.wcl.nullmusic.ui.fragment;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

/**
 * Created by dllo on 16/1/4.
 */
public class FragmentFactory {
    private static FragmentFactory fragmentFactory;
    private static SparseArray<Fragment> fragmentMap = new SparseArray<>();

    private FragmentFactory() {
    }

    public static FragmentFactory getInstance() {
        if (fragmentFactory == null) {
            fragmentFactory = new FragmentFactory();
        }
        return fragmentFactory;
    }

    public static Fragment createFragment(int position) {
        Fragment fragment = fragmentMap.get(position);
        if (fragment == null) {
            switch (position) {
                case 0:
                    fragment = new MyMusicFragment();
                    break;
                case 1:
                    fragment = new RecommendFragment();
                    break;

                case 2:
                    fragment = new SongMenuFragment();
                    break;
                case 10:
                    fragment = new PicFragment();
                    break;
                case 11:
                    fragment = new LyricFragment();
                    break;

            }
            fragmentMap.put(position, fragment);
        }
        return fragment;
    }


}
